package kr.hyunist.androidcomplete02saeildamil.ch20;

import kr.hyunist.androidcomplete02saeildamil.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.Button;
import android.widget.TextView;

public class CounterFragment extends Fragment {
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.counterfragmenttest, container, false);
		
		Button btnIncrease = (Button) root.findViewById(R.id.counterfragmenttestbtn);
		final TextView textCounter = (TextView) root.findViewById(R.id.counterfragmenttesttv);
		
		//상태저장
		if(savedInstanceState != null){
			textCounter.setText(Integer.toString(savedInstanceState.getInt("counter")));
		}
		
		btnIncrease.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int count = Integer.parseInt(textCounter.getText().toString());
				textCounter.setText(Integer.toString(count + 1));
			}
			
		});
		
		return root;
	}

	//상태저장
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		
		TextView textCounter = (TextView) getView().findViewById(R.id.counterfragmenttesttv);
		int a = Integer.parseInt(textCounter.getText().toString());
		outState.putInt("counter", a);
		
	}
	
	
}
